import 'package:example/pages/pages/ClickScanPage.dart';
import 'package:example/pages/pages/ListImagePage.dart';
import 'package:example/pages/pages/ListViewTextFieldPage.dart';
import 'package:example/pages/pages/MsgListPage.dart';
import 'package:example/pages/viewModel/HomeViewModel.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:hx_base/pages/BaseTextField.dart';
import 'package:hx_base/pages/BaseToast.dart';
import 'package:hx_base/pages/EmptyFailView.dart';
import 'package:hx_base/pages/ExpandAnimationView.dart';
import 'package:hx_base/pages/UploadFileView.dart';
import 'package:hx_base/pages/UploadImageView.dart';
import 'package:hx_base/pages/filelistview/FileListView.dart';
import 'package:hx_base/pages/imagelistview/hx_imagelistview.dart';
import 'package:hx_base/utils/LoggerUtil.dart';
import 'package:hx_base/utils/PermissionCheckUtils.dart';

class HomePage extends StatelessWidget {
  HomePage({super.key});

  HomeViewModel viewModel = Get.put(HomeViewModel());

  List list = [
    "http://gips3.baidu.com/it/u=3886271102,3123389489&fm=3028&app=3028&f=JPEG&fmt=auto?w=1280&h=960",
    "http://gips3.baidu.com/it/u=1821127123,1149655687&fm=3028&app=3028&f=JPEG&fmt=auto?w=720&h=1280",
    "http://gips2.baidu.com/it/u=195724436,3554684702&fm=3028&app=3028&f=JPEG&fmt=auto?w=1280&h=960",
  ];

  List fileList = [
    {
      "name": "pdf文件",
      "type": ".pdf",
      "url":
          "http://gips2.baidu.com/it/u=195724436,3554684702&fm=3028&app=3028&f=JPEG&fmt=auto?w=1280&h=960",
    },
    {
      "name": "word 文件",
      "type": ".doc",
      "url":
          "http://gips2.baidu.com/it/u=195724436,3554684702&fm=3028&app=3028&f=JPEG&fmt=auto?w=1280&h=960",
    },
    {
      "name": "表格文件",
      "type": ".xlsx",
      "url":
          "http://gips2.baidu.com/it/u=195724436,3554684702&fm=3028&app=3028&f=JPEG&fmt=auto?w=1280&h=960",
    },
    {
      "name": "TXT 文件",
      "type": ".txt",
      "url":
          "http://gips2.baidu.com/it/u=195724436,3554684702&fm=3028&app=3028&f=JPEG&fmt=auto?w=1280&h=960",
    },
    {
      "name": "这个也不知道是什么文件不知道能不能访问",
      "type": ".pd",
      "url":
          "http://gips2.baidu.com/it/u=195724436,3554684702&fm=3028&app=3028&f=JPEG&fmt=auto?w=1280&h=960",
    },
  ];

  var account = "".obs;

  var phone = "".obs;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("首页"),
      ),
      body: bodyView(),
    );
  }

  bodyView() {
    return SingleChildScrollView(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            width: double.infinity,
            margin: EdgeInsets.all(10),
            child: Text("方法示例"),
          ),
          Wrap(
            spacing: 10,
            children: [
              ElevatedButton(
                  onPressed: () {
                    BaseToast.showToast("弹框");
                  },
                  child: Text("弹框")),
              ElevatedButton(
                onPressed: () {
                  BaseToast.showSuccess("成功弹框提示");
                },
                child: Text("点击弹框"),
              ),
              ElevatedButton(
                onPressed: () {
                  BaseToast.showError("失败弹框提示");
                },
                child: Text("点击弹框"),
              ),
              ElevatedButton(
                onPressed: () {
                  BaseToast.showInfo("感叹号弹框提示");
                },
                child: Text("点击弹框"),
              ),
              ElevatedButton(
                onPressed: () {
                  BaseToast.show("菊花弹框提示");
                  Future.delayed(const Duration(seconds: 4))
                      .then((onValue) => {BaseToast.cancel()});
                },
                child: Text("菊花弹框提示"),
              ),
            ],
          ),
          ElevatedButton(
            onPressed: () async {
              Log.w(await PermissionCheckUtils.camera("权限判断"));
            },
            child: Text("权限判断"),
          ),
          ElevatedButton(
            onPressed: () {
              Get.to(() => ClickScanPage());
            },
            child: Text(
              "扫描",
            ),
          ),
          ElevatedButton(
            onPressed: () {
              Get.to(() => MsgListPage());
            },
            child: Text("闪光"),
          ),
          ElevatedButton(
            onPressed: () {
              Get.to(() => ListImagePage());
            },
            child: Text("图片列表"),
          ),
          ElevatedButton(
            onPressed: () {
              Get.to(() => ListViewTextFieldPage());
            },
            child: Text("多列表输入框"),
          ),
          ElevatedButton(
            onPressed: () {
              viewModel.account.value = "1234";
              viewModel.update(["refresh"]);
            },
            child: Text("刷新输入框"),
          ),
          GetBuilder<HomeViewModel>(
            id: "refresh",
            builder: (context) {
              return BaseTextField(
                text: viewModel.account.value,
                hintText: "请输入账号",
                contentPadding:
                    EdgeInsets.symmetric(vertical: 5.h, horizontal: 20.w),
                callBackValue: (value) => account.value = value,
                keyboardType: TextInputType.text,
              );
            },
          ),
          BaseTextField(
            text: phone.value,
            hintText: "请输入手机号",
            contentPadding:
                EdgeInsets.symmetric(vertical: 5.h, horizontal: 20.w),
            keyboardType: TextInputType.number,
            callBackValue: (callBackValue) => phone.value = callBackValue,
          ),
          ExpandAnimationView(
            decoration: BoxDecoration(color: Colors.yellow),
            titleView: Text("基本信息"),
            isExpand: true,
            contentView: Container(
              width: double.infinity,
              height: 100,
              color: Colors.red,
              child: Text("很多内容"),
            ),
          ),
          UploadImageView(
            cameraReason: "相机权限使用：\n拍照",
            photoReason: "相册权限调用:\n 选取照片",
            width: (ScreenUtil().screenWidth - 50) / 3,
            height: 100,
            callbackImage: (imageList) {},
            maxlength: 2,
            margin: EdgeInsets.symmetric(horizontal: 10),
          ),
          UploadFileView(
            reason: "文件权限使用:选择文件",
            margin: EdgeInsets.all(10),
            crossAxisAlignment: CrossAxisAlignment.start,
            callbackFile: (fileList) {},
          ),
          Container(
            margin: EdgeInsets.fromLTRB(10, 10, 10, 10),
            child: Text("图片列表展示"),
          ),
          HxImagelistview(
            list: list,
            getImageUrl: (item) => item,
            width: (ScreenUtil().screenWidth - 50) / 3,
            height: 100,
            margin: EdgeInsets.symmetric(horizontal: 10),
          ),
          FileListView(
            list: fileList,
            getFileUrl: (item) => item["url"],
            getFileType: (item) => item["type"],
            getFileName: (item) => item["name"],
          ),
          SizedBox(
            width: double.infinity,
            height: 300,
            child: EmptyFailView(
              tip: "暂无数据",
              // imageName: "assets/images/IMG_9210.PNG",
            ),
          ),
        ],
      ),
    );
  }
}
